package edu.tec.mty.test.nemesis;

import java.util.HashMap;

import edu.tec.mty.core.Commands;
import edu.tec.mty.core.Controller;
import edu.tec.mty.core.modules.Game;
import edu.tec.mty.core.modules.Self;
import edu.tec.mty.core.modules.models.BallModel;
import edu.tec.mty.core.modules.models.BallModelFactory;
import edu.tec.mty.core.modules.models.WorldModel;
import edu.tec.mty.core.modules.models.WorldModelFactory;
import edu.tec.mty.playModes.PlayMode;
import edu.tec.mty.test.nemesis.playModes.BeforeKickOff;
import edu.tec.mty.test.nemesis.playModes.PlayOn;
import edu.tec.mty.test.nemesis.players.Dummy;

public class Agent {

	public static void main(String[] args) {
		HashMap<String, PlayMode> gameStates = new HashMap<String, PlayMode>();
		Controller controller = new Controller();
		controller.setTeamName("Nemesis");
		controller.setTypeOfAgent('p');
		try {
			controller.connect("localhost");
			Commands commands = controller.getReferenceToCommands();
			WorldModelFactory worldModelFactory = controller.getReferenceToWorldModel();
			BallModelFactory ballModelFactory = controller.getReferenceToBallModel();
			Game game = controller.getReferenceToGame();
			Self player = controller.getReferenceToPlayer();
			gameStates.put("before_kick_off", new BeforeKickOff());
			gameStates.put("play_on", new PlayOn());
			Dummy dummy = new Dummy(commands, game, player);
			boolean running = true;
			while (running) {
				long step = game.getStep();
				BallModel ballModel = ballModelFactory.getBallModel();
				WorldModel worldModel = worldModelFactory.getWorldModel();
				if (gameStates.containsKey(game.getPlayMode())) {
					gameStates.get(game.getPlayMode()).perform(dummy, ballModel, worldModel);
				}
				if (Game.GAME_TIME > 150) {
					running = false;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		controller.disconnect();
	}
	
}
